#* Author: Wady <iswady@163.com>
#* Date:   Wed May 15 12:00:00 2019

option(ENABLE_TESTER_LOG "Enable logger of tester." ON)

if(ENABLE_TESTER_LOG)
    add_definitions(-DENABLE_TESTER_LOG=1)
else()
    add_definitions(-DENABLE_TESTER_LOG=0)
endif()

if(ENABLE_GENERATE_TEST_CODE)
	execute_process(COMMAND python pythons/ClipMediaMsgHeadTesterConvertFileGenerate.py ${CMAKE_INSTALL_FULL_INCLUDEDIR}/msghead/common_param.h tester_common_param 
		${CMAKE_CURRENT_BINARY_DIR}/tester_mgr_msghead.h ${CMAKE_CURRENT_BINARY_DIR}/tester_mgr_msghead.c WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif()

add_subdirectory(plugins)

set(TESTER_SOURCE_FILES_C
    ${PLUG_O_SOURCE_FILES_C}
    tester_common.c
    tester_iters.c
    tester_libs.c
    tester_main.c
    tester_manage.c
    tester_mgr_call.c
    tester_mgr_face.c
    tester_mgr_ipc.c
    tester_mgr_monitor.c
    tester_mgr_qrcode.c
    tester_mgr_sound.c
    tester_shell.c
    tester_mgr_configs.c
    tester_mgr_photo.c
    tester_mgr_message.c
    tester_mgr_lm.c
    tester_mgr_plugs.c
    tester_mgr_others.c
    tester_logger.c
)

if(ENABLE_GENERATE_TEST_CODE)
	list(APPEND TESTER_SOURCE_FILES_C ${CMAKE_CURRENT_BINARY_DIR}/tester_mgr_msghead.c)
endif()

set(TESTER_LIBS
    ${CJSON_LIBRARIES}
    ${CMAKE_THREAD_LIBS_INIT}
    ${LOGGER_LIBRARIES}
    ${COMMON_LIBRARIES}
    ${MSGCLIENT_LIBRARIES}
    m
)

if(ENABLE_MEMWATCH)
    list(APPEND TESTER_LIBS ${MEMWATCH_LIBRARIES})
endif()

set(TESTER_INCLUDE_DIRS
	${CMAKE_CURRENT_BINARY_DIR}
	${CMAKE_CURRENT_LIST_DIR}
)

if(TOOLBOX_FOUND)
    list(APPEND TESTER_LIBS ${TOOLBOX_LIBRARIES})
    list(APPEND TESTER_INCLUDE_DIRS ${TOOLBOX_INCLUDE_DIRS})
endif()

use_c99()

utils_apply_compile_flags(TESTER_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)

add_executable(media_tester ${TESTER_SOURCE_FILES_C})
target_link_libraries(media_tester ${TESTER_LIBS})
target_include_directories(media_tester PRIVATE ${TESTER_INCLUDE_DIRS})

install(TARGETS media_tester
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
